package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;

import com.bumptech.glide.Glide;
import com.example.mywood.R;

import java.util.List;

import bean.ApplicationDataBean;
import myapp.MyApp;
import myview.HorizontalListView;
import util.ZoomImageview;

import static com.facebook.FacebookSdk.getApplicationContext;

/**
 * Created by fei on 2017/12/30.
 */

public class MyAdapter extends PagerAdapter {
    private Context context;
    private List<String> list;
    public MyAdapter(Context context, List<String> list) {
        super();
        this.context = context;
        this.list = list;
    }
    //总数
    @Override
    public int getCount() {
        int count  = 0;
        if (list.size() > 1){
            count = Integer.MAX_VALUE;
        }else{
            count = list.size();
        }
        return count;//最大值
    }
    //得到的视图与添加进来的是否一致  如果一致 返回true
    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0==arg1;
    }
    //创建视图
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        //创建ImageView
        ZoomImageview imageView = new ZoomImageview(context);
        //设置图片  src 按照比例进行展示图片  Background  全部充满展示
//        imageView.setImageResource(list.get(position%list.size()));//通过取模的形式 在list集合中取出图片
//        if (position < list.size()){
            Glide.with(getApplicationContext()).load(list.get(position%list.size())).into(imageView);

//        }
        //getResources res文件
//		imageView.setBackground(context.getResources().getDrawable(list.get(position)));
        //拉伸
//        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        container.addView(imageView);

        return imageView;
    }
    //删除视图
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
